﻿using System;
using System.Collections.Generic;
using System.Text;

namespace TCCHWLib.Commands
{
    public class EqualCommand : ICommand
    {

        public EqualCommand(object parameter1, ParameterType parameterType1, object parameter2, ParameterType parameterType2)
        {
            m_Operand1 = parameter1;
            m_Operand2 = parameter2;
            m_Type1 = parameterType1;
            m_Type2 = parameterType2;
            m_ExOperand1 = parameter1;
            m_ExOperand2 = parameter2;
            m_ExType1 = parameterType1;
            m_ExType2 = parameterType2;
            this.Value = false;
        }
        public override object Execute(Processor processor)
        {
            double op1 = Convert.ToDouble(m_ExOperand1);
            double op2 = Convert.ToDouble(m_ExOperand2);
            if (op1 == op2)
                m_Value = 0;
            else
                m_Value = 1;
            return this.Value;
        }

        public override string ToString()
        {
            string val1 = "";
            string val2 = "";
            switch (m_Type1)
            {
                case ParameterType.Value:
                    val1 = "{" + m_Operand1 + "}";
                    break;
                case ParameterType.Address:
                    val1 = "[" + m_Operand1 + "]";
                    break;
                case ParameterType.Instruction:
                    val1 = "i" + m_Operand1;
                    break;
                case ParameterType.Null:
                    val1 = "NULL";
                    break;
                default:
                    val1 = m_Operand1.ToString();
                    break;
            }
            switch (m_Type2)
            {
                case ParameterType.Value:
                    val2 = "{" + m_Operand2 + "}";
                    break;
                case ParameterType.Address:
                    val2 = "[" + m_Operand2 + "]";
                    break;
                case ParameterType.Instruction:
                    val2 = "i" + m_Operand2;
                    break;
                case ParameterType.Null:
                    val2 = "NULL";
                    break;
                default:
                    val2 = m_Operand2.ToString();
                    break;
            }

            return String.Format("EQUALS ( {0} , {1} )", val1, val2);
            //return base.ToString() + String.Format("> next pc{0}", NextPC);
        }


    }
}
